<?php
#============================
#	Filename: tagslist.qgmod.php
#	Note	: Note
#	Version : 1.0
#	Author  : ovsexia
#	Update  : 2017-08-31
#============================
global $FS,$DB,$PA,$prefix,$bi;
$md5 = md5(TemplateID."_".$id."_".$length."_".$limit);
$cache_file = "data/cache/list_".$md5.".php";#[缓存文件]
$check_status = false;
if($iscache)
{
	$check_status = CheckCache($cache_file);#[判断缓存文件的存储状态]
}
if($check_status)
{
	include_once($cache_file);
	unset($cache_file);
	return $list;
}
#[取得信息]
$rs = $DB->qgGetOne("SELECT * FROM ".$prefix."msg WHERE id='".$id."'");
if($rs["tags"])
{
	$tags_arr = explode(',',$rs["tags"]);
	$condition .= " WHERE cateid='".$rs["cateid"]."' AND subject LIKE ";
	foreach($tags_arr AS $key=>$value)
	{
		if($key != 0)
		{
			$condition .= " OR subject LIKE ";
		}
		$condition .= "'%".$value."%'";
	}
	
	$sql = "SELECT * FROM ".$prefix."msg ".$condition." LIMIT 0, ".$limit."";
	$list = $DB->qgGetAll($sql);
	if(!$list)
	{
		unset($cache_file);
		return false;
	}
	$i = 1;
	foreach($list AS $key=>$value)
	{
		$sql = "SELECT * FROM ".$prefix."msg_content WHERE id='".$value["id"]."' ";
		$rsc = $DB->qgGetOne($sql);
		/*清除标签*/	
		$value["allcontent"] = $rsc["content".$bi];
		$value["content"] = strip_tags($rsc["content".$bi]);
		$value["content"] = CutString(str_replace(array("<p>","</p>","<div>","</div>","<br />","&nbsp;","　"),array("","","","","","",""),$value["content"]),$words);
		
		$value["folder"] = $value["u_folder"];
		$value["filename"] = $value["u_filename"];
		$value["markfile"] = $value["u_markfile"];
		$value["thumbfile"] = $value["u_thumbfile"];
		unset($value["u_folder"],$value["u_filename"],$value["u_markfile"],$value["u_thumbfile"]);
		
		$sql = "SELECT catename,catename_en,catename_ft FROM ".$prefix."category WHERE id='".$value["cateid"]."' ";
		$rsc = $DB->qgGetOne($sql);
		$value["catename"] = $rsc["catename".$bi];
		$value["catename_en"] = $rsc["catename_en"];
		
		#[获取自定义字段]
		$value["fieldlist"] = $PA->fieldlist($value["id"]);
		if($value["fieldlist"])
		{
			foreach($value["fieldlist"] AS $key2=>$value2)
			{
				$value[$value2["sign"]] = $value2["field_content"];
			}
		}
	
		#[月份转换]
		$value["day"] = date("d",$value["postdate"]);
		$value["month"] = monthc(date("m",$value["postdate"]),"min"); //[min] or [ful]
		
		$value["row_index"] = $i;

		//首项尾项
		if($key==0)
		{
			$value["first"] = true;
		}
		if($key==count($list)-1)
		{
			$value["last"] = true;
		}

		$rslist[] = $value;
		$i++;
	}
	
	$msglist = _____QGMODULE_CLEARUP_LIST($rslist,$length,true);
	$list["list"] = $msglist;
	
	$FS->qgWrite($list,$cache_file,"list");
	unset($rslist,$msglist,$cache_file);
	return $list;
}
?>